package com.bensonbasement.snorflux.server.world.prototypes;

import java.util.LinkedList;
import java.util.List;

import com.bensonbasement.snorflux.server.verbs.Verb;

public class EntityPrototype extends WorldElementPrototype {
	public static final EntityPrototype ENTITY;
	static {
		ENTITY = new EntityPrototype("core_entity",WorldElementPrototype.WORLDELEMENT);
	}
	
	private List<Verb> verbs = new LinkedList<Verb>();
	
	private EntityPrototype(String prototypeID, WorldElementPrototype parent) {
		super(prototypeID, parent);
	}
	
	public EntityPrototype(String prototypeID, EntityPrototype parent) {
		super(prototypeID, parent);
	}
	
	public Verb getVerb(String verbName) {
		for (Verb verb : this.verbs) {
			if (verb.getVerbName().equals(verbName)) {
				return verb;
			}
		}
		WorldElementPrototype parent = this.getParent();
		if (parent instanceof EntityPrototype) {
			return ((EntityPrototype)parent).getVerb(verbName);
		}
		else {
			throw new RuntimeException("Verb not found: "+verbName);
		}
	}
	
	public List<Verb> getAllVerbs() {
		// TODO: Make this only return one copy of any redundant verbs (verbs that are overridden in the parent).
		LinkedList<Verb> retVal = new LinkedList<Verb>(verbs);
		WorldElementPrototype parent = this.getParent();
		if (parent instanceof EntityPrototype) {
			retVal.addAll(((EntityPrototype)parent).getAllVerbs());
		}
		return retVal;
	}
	
	public void addVerb(Verb verb) {
		verbs.add(verb);
	}
}
